doseresNMA antidep/data.clean.R

#!! check if out 3 is needed
# functions to remove NA's and single arm trials

# 1. remove NA's
removeNAdosresdata.fun=function(dataset)
{# this function takes a database and exclude studies that will cause problems in fiting the dosres model for a particular outcome

  r=eval(substitute(r), dataset)
  dose=eval(substitute(dose), dataset)
  n=eval(substitute(n), dataset)
  studyid=eval(substitute(studyid), dataset)

  # 1. exclude studies with NA or zero events
  out1=unique(studyid[is.na(r)|r ==0])

  # 2. exclude studies with  NA sample size
  out2=unique(studyid[is.na(n)])

  # # 3. exclude those studies with the same dose in all arms
   out3=unique(studyid)[tapply(dose,studyid,max)==tapply(dose,studyid,min)]

  # 4. exclude those studies with NA dose
  out4=unique(studyid[is.na(dose)])

  # 5. exclude studies that report the same dose in two arms
  out5=unique(studyid)[sapply(unique(studyid), function(x) sum(table(dataset$dose[which(dataset$studyid==x)])>1))==1]

  # add column with include/exclude studies T/F
  dataset$exclude <- ifelse(studyid%in%c(out1,out2,out3,out4,out5),TRUE,FALSE)
  return(list(dataset=dataset,out=c(out1,out2,out3,out4,out5)))
}

# 2.single arm trials( remove NA's first)
exludesinglearmsdata.fun<-function(dataset,studyid)
{
  studyid=eval(substitute(studyid), dataset)
  singlearmstudies=names(table(studyid))[table(studyid)<2]
  dataset2=dataset[is.na(match(studyid,singlearmstudies)),]
  dataset2
  #returns a dataset with the same columns after excluding single arms
}
htx-r/doseresNMA documentation built on Jan. 28, 2021, 5:32 a.m.